<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class SellController extends Controller
{



    public $id_file;


    public function filters()
    {
        return array(
            'accessControl',
        );
    }

    public function accessRules() {
        return array(
			array('deny',
				'actions' => array('Getsell'),
				'users'=>array('?'),
			),
		);
    }

    public function actionGetsell() {
        $sell_f = new SellForm();
        if (isset($_POST['SellForm'])) {
            
            foreach ($_POST['SellForm'] as $name => $value) {

                $sell_f->$name = $value;
            }
            if ($sell_f->validate())
            {
            $sell = new sell();
            $sell->id_type = $sell_f->type;
            $sell->subjekt = $sell_f->subjekt_s;

            $sell->cost = $sell_f->cost;
            $sell->vol_start = $sell_f->vol_start;
            $sell->vol_end = $sell_f->vol_end;
            $sell->text = $sell_f->text;
            $sell->srok = $sell_f->srok;
            $sell->name = $sell_f->name;
            $user=new User();
            $sell->id_user=Yii::app()->user->getId();
            
            $id_file = CUploadedFile::getInstance($sell_f, 'id_file');
            if ($id_file!=null)
             {
                $id_file->saveAs('file/sell/'.$id_file);
            }
            
            $sell->id_file=$id_file;
            $sell->save();

            $user=user::model()->findByPk(Yii::app()->user->getId());
            $count_sell=$user->user_info->sell;
            $user->user_info->sell=$count_sell+1;
            $user->user_info->save();
            }
            else
            {
               
            }
        }
        $typ = type::model()->findAll(
                        array('order' => 'type_name'));

// при помощи listData создаем массив вида $ключ=>$значение
        $list = CHtml::listData($typ,  'id_type', 'type_name');
                       

        $this->render('sell', array('list' => $list, 'sell' => $sell_f));
    }

}
?>
